package com.lbj.dao.impl;

import com.lbj.dao.AdminDao;
import com.lbj.domain.Admin;
import com.lbj.utils.JDBCUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class AdminDaoImpl implements AdminDao {

    JDBCUtil jdbcUtil = new JDBCUtil();
    Connection conn = jdbcUtil.createCon();
    @Override
    public Admin login(String loginAct, String loginPwd) {
        Admin admin = null;
        String sql = "select * from tbl_admin where loginAct=? and loginPwd=?";
        ResultSet rs = null;
        try {
            PreparedStatement pst = jdbcUtil.createStatement(sql);
            pst.setString( 1, loginAct);
            pst.setString(2, loginPwd);
            rs = pst.executeQuery();
            while (rs.next()) {
                String id = rs.getString(1);
                String name = rs.getString(3);
                admin = new Admin(id, loginAct,name,loginPwd );
            }
            rs.close();
            pst.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return admin;
    }
}
